<#define __SERVER__="{{LAM.SERVER}}" />
<#define __COMPONENTS__="{{LAM.COMPONENTS}}" />
#define# __DATA__ <#include repeat="0" tp-data="{}"  file="__SERVER__/sorts/index" /> #end#


<#define _TITLE_="修改地址" />

<#extends title="_TITLE_" data="{'list':[
{'name':'网页地址','href':'###','title':''},
{'name':'网页地址','href':'###','title':''},
{'name':'_TITLE_'}
]}" />

<#Block:begin id="crumb" data="{'list':[
{'name':'网页地址','href':'###','title':''},
{'name':'网页地址','href':'###','title':''},
{'name':'_TITLE_'}
]}">
<#Block:end>

<#include repeat="0" tp-data="{}"  file="__COMPONENTS__/selectBox2.html" />
<#Block:begin id="url_form" data="{'id':'0','pid':'0','name':''}">
<form class="form-horizontal" action="__SERVER__/sorts/edit?id=<%=id%>" method="post">
    <input type="hidden" name="id" value="<%=id%>">
    <div class="sectionWrap-A5">
        <div class="p15">
            <div class="sectionForm-A1 sectionForm-A1-1 sectionForm-A1-1-1 mb15">
                <span data-error="id" class="help-block none"></span>
                <ul>
                    <li class="clear mb5">
                        <label class="L">类别：<span class="warning">*</span></label>
                        <%=LAM.Template.getBlock("selectBox",{'list':__DATA__, 'name':'pid', 'pid': pid})%>
                        <span data-error="pid" class="help-block none"></span>
                    </li>
                    <li class="clear mb5">
                        <label class="L">名称：<span class="warning">*</span></label>
                        <input type="text" name="name" class="text name L" value="<%=name%>">
                        <span data-error="name" class="help-block none"></span>
                    </li>


                </ul>
            </div>
            <div class="clear mb10 sectionForm-A1 sectionForm-A1-1-1 sectionForm-A2 ml50">
                <button type="submit" class="btn save L mr15">修改</button>
                <button type="reset" class="btn btn-cancel L">恢复</button>
            </div>
        </div>
    </div>
</form>
<#Block:end>
<div id="url_form"></div>

<script type="text/javascript">

    LAM.run([jQuery],function($) {
        'use strict';
        var System = this;
        var id = System.get('id');

        function getByName(name) {
            return document.getElementsByName(name)[0].value;
        }

        function init() {
            $('form').submit(function () {
                $('[data-error]').hide();
                var sid  = getByName("pid");
                var name = getByName("name");

                $[this.method](this.action,{
                    'pid':sid,
                    'name':name
                },function(data){
                    if(data.status){
                        alert(data.message);
                        System.redirect(System.INDEX+"sorts/index");
                    }else{
                        alert(data.message);
                        System.each(data.errors,function (key,value) {
                            $('[data-error="'+key+'"]').text(value).show();
                        });
                    }
                },'json');

                return false;
            });
        }

        $(function(){
            $.get("__SERVER__/sorts/show",{
                'id':id
            },function(data){
                if(data.status){
                    data.data.sid = data.data.sorts_id;
                    $('#url_form').html(System.Template.getBlock("url_form",data.data));
                    init();
                }else{
                    alert(data.message);
                }
            },'json');




        });
    });
</script>